from datetime import datetime

from models import db



# 用户表
class User(db.Model):
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)
    user_name = db.Column(db.String(64),nullable=False)
    user_password = db.Column(db.String(64),nullable=False)



# 图片表
class Photo(db.Model):
    __tablename__ = 'photos'

    id = db.Column(db.Integer,primary_key=True)
    photo_path = db.Column(db.String(128),nullable=False)
    # 对照片的描述
    photo_dig_title = db.Column(db.String(60), nullable=True)
    photo_dig = db.Column(db.TEXT, nullable=True)
    # 上传的时间
    create_time = db.Column(db.DateTime, default=datetime.now,nullable=True)
    user_id = db.Column(db.Integer, db.ForeignKey("users.id"))  # 当前新闻的作者id
    user = db.relationship('User',backref=db.backref('photos',lazy='dynamic'))


# 相册分类表
class Photo_class(db.Model):

    __tablename__ = 'photo_class'

    id = db.Column(db.Integer, primary_key=True)

    name = db.Column(db.String(64),nullable=False)

    user_id = db.Column(db.Integer, db.ForeignKey("users.id"))  # 当前新闻的作者id

    user = db.relationship('User', backref=db.backref('photo_class', lazy='dynamic'))
